import { createRouter, createMemoryHistory, useRoute } from 'vue-router'
import useConversationStore from '../store/modules/converstaionStore'
export const router = createRouter({
  history: createMemoryHistory(),
  routes: [
    {
      path: '/',
      component: () => import('../views/home.vue')
    },
    {
      path: '/setting',
      component: () => import('../views/setting.vue')
    },
    {
      path: '/chat',
      component: () => import('../views/chat.vue')
    }
  ]
})
router.afterEach((to, from) => {
  const conversationStore = useConversationStore()
  const route = useRoute()
  if (to.path === '/chat') {
    conversationStore.setSelectId(Number(route.query.id))
  } else {
    conversationStore.setSelectId(-1)
  }
})
